//
//  SecondViewController.m
//  WangLottery
//
//  Created by leven hu on 12-4-22.
//  Copyright 2012年 __MyCompanyName__. All rights reserved.
//

#import "SecondViewController.h"

@implementation SecondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    
    lotteryStyle=[[NSMutableArray alloc]init];
    
    for (int i=0; i<4; i++) {
    
        NSMutableDictionary *dic=[[NSMutableDictionary alloc]init];
        
        switch (i) {
            case 0:
                [dic setObject:@"双色球" forKey:@"type"];
                [dic setObject:@"第2012081期 开奖日期2012-07-12" forKey:@"info"];
                [dic setObject:@"020510242529" forKey:@"red"];
                [dic setObject:@"06" forKey:@"blue"];
                break;
            case 1:
                [dic setObject:@"7星彩" forKey:@"type"];
                [dic setObject:@"第12080期 开奖日期2012-07-11" forKey:@"info"];
                [dic setObject:@"1112142528" forKey:@"red"];
                [dic setObject:@"0205" forKey:@"blue"];
                break;
            case 2:
                 [dic setObject:@"3D" forKey:@"type"];
                 [dic setObject:@"第2012080期 开奖日期2012-07-11" forKey:@"info"];
                 [dic setObject:@"247" forKey:@"red"];
                break;
            case 3:
                [dic setObject:@"七乐彩" forKey:@"type"];
                [dic setObject:@"第12186期 开奖日期2012-07-11" forKey:@"info"];
                [dic setObject:@"673" forKey:@"red"];
                break;
            default:
                break;
        }
        
        [lotteryStyle addObject:dic];
        
        [dic release];
        
        UIButton *fresh = [UIButton buttonWithType:UIButtonTypeCustom];
        [fresh setFrame:CGRectMake(0, 0, 60, 60)];
        [fresh setBackgroundColor:[UIColor greenColor]];
        self.navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:fresh];
        [fresh setTitle:@"Fresh" forState:UIControlStateNormal];
        //[fresh release];
    }
    
}

- (void)dealloc{

    [lotteryStyle release];
    
    [super dealloc];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
 
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    UIButton *refresh = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [refresh setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    refresh.frame=CGRectMake(0, 0, 40, 40);
    [refresh addTarget:self action:@selector(refreshView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:refresh];
    self.navigationItem.leftBarButtonItem = btn;
    [btn release];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

#pragma tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [lotteryStyle count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *string=@"Mr.hu";
    DrawLotteryCell *cell=[[[DrawLotteryCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:string]autorelease];
    
    [cell setCellFrame];
    
    if (indexPath.row == 0) 
        [cell.lotterType setImage:[UIImage imageNamed:@"doublecolorBoll.png"]];
    else if(indexPath.row == 1)
         [cell.lotterType setImage:[UIImage imageNamed:@"7star.png"]];
    else if(indexPath.row == 2)
         [cell.lotterType setImage:[UIImage imageNamed:@"3d.png"]];
    else if(indexPath.row == 3)
        [cell.lotterType setImage:[UIImage imageNamed:@"7happy.png"]];
    

    NSDictionary *_dic=[lotteryStyle objectAtIndex:indexPath.row];
    
    cell.lotterName.text=[_dic objectForKey:@"type"];
    cell.lotterInfo.text=[_dic objectForKey:@"info"];

    NSString *str=[_dic objectForKey:@"red"];
    
    if (str) {
        cell.lotterRadNum=str;
    }
    
    str=nil;
    
    str=[_dic objectForKey:@"blue"];
    
    if (str) {
        cell.lotterBlueNum=str;
    }

    return  cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return YES;
}

- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
 
    return 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setSelected:NO];
    NewLottery *viewController = [[NewLottery alloc] initWithNibName:@"NewLottery" bundle:nil];
    viewController.title=@"最新开奖";
    [self.navigationController pushViewController:viewController animated:YES];
    [viewController release];
}

#pragma mark －刷新按钮

- (void)refreshView{

    
}

@end
